﻿using System.Linq;
using System.Security.Claims;

namespace FrameWork
{
   public static class UserInfo
   {
       public static long LoginId
       {
            get
            {
                var loginId = TimHttpContext.Context.User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier))?.Value;
                return string.IsNullOrWhiteSpace(loginId) ? 0 : long.Parse(loginId);
            }
        }

       public static string LoginName
       {
            get
            {
                return TimHttpContext.Context.User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimTypes.Name))?.Value;
            }
        }
       public static string Ip
       {
            get
            {
                var ip = TimHttpContext.Context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
                return !string.IsNullOrEmpty(ip) ? ip : TimHttpContext.Context.Connection.RemoteIpAddress.ToString();
            }
        }
    }
}
